package com.video.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.video.bean.Type;
import com.video.bean.UserInfo;
import com.video.bean.Vip;
import com.video.dao.TypeDao;
import com.video.dao.UserInfoDao;
import com.video.service.TypeServiceI;
import com.video.utils.ResultMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class TypeServiceImpl implements TypeServiceI {
    @Autowired
    private TypeDao typeDao;

    @Override
    public ResultMap selectAllTypeByLimit(int page, int limit) {
        PageHelper.startPage(page, limit);//开启分页
        List<Type> list = typeDao.selectAllType();
        PageInfo<Type> pageInfo = new PageInfo<Type>(list);
        list = pageInfo.getList();
        return ResultMap.selectLimitBySuccess(0,pageInfo.getTotal(),list);
    }

    @Override
    public ResultMap selectAllType() {
        List<Type> list = typeDao.selectAllType();
        return ResultMap.createBySuccess(list);
    }

    @Override
    public ResultMap createType(String typeStr) {
        Type type = JSONObject.parseObject(typeStr,Type.class);
        type.settId(UUID.randomUUID().toString());
        typeDao.createType(type);
        return ResultMap.createBySuccess();
    }

    @Override
    public ResultMap deletetypeByTid(String tId) {
        //这里要加业务逻辑
        typeDao.deletetypeByTid(tId);
        return ResultMap.createBySuccess();
    }

    @Override
    public ResultMap updatetypeByTId(String typeStr) {
        Type type = JSONObject.parseObject(typeStr,Type.class);
        typeDao.updatetypeByTId(type);
        return ResultMap.createBySuccess();
    }
}
